package com.example.jussi.hotfixdemo;

import android.app.Application;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

import com.alipay.euler.andfix.patch.PatchManager;

import java.io.File;
import java.io.IOException;

/**
 * Created by admin on 2018/12/9.
 */

public class MyApplication extends Application {
    private static final String TAG = "MyApplication";
    /**
     * apatch文件
     */
    private static final String APATCH_PATH= "/Out.apatch";
    private PatchManager mPatchManager;

    @Override
    public void onCreate(){
        super.onCreate();   // 初始化
        mPatchManager = new PatchManager(this);
        mPatchManager.init("1.0");  // 版本号
        // 加载 apatch
        mPatchManager.loadPatch();
        //apatch文件的目录
        String patchFileString = Environment.getExternalStorageDirectory().getAbsolutePath()+ APATCH_PATH;
        File apatchPath = new File(patchFileString);
        if (apatchPath.exists()){
            Log.e(TAG, "补丁文件存在");
            Toast.makeText(getApplicationContext(),"补丁文件存在", Toast.LENGTH_SHORT).show();
            try {
                //添加apatch文件
                mPatchManager.addPatch(patchFileString);
            } catch (IOException e) {
                Log.e(TAG, "打补丁出错了");
                Toast.makeText(getApplicationContext(),"打补丁出错了"+e.toString(), Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        } else {
            Log.e(TAG, "补丁文件不存在");
            Toast.makeText(getApplicationContext(),"补丁文件不存在", Toast.LENGTH_SHORT).show();
        }
    }
}
